﻿create procedure dbo.GetTakeoutProvider
(
		@TakeoutProviderID int
	)

AS

SET NOCOUNT ON
	-- Takeout Provider
	SELECT     Id, MenuID, PaymentSourceID, UserID, ExpirationTime, StartTime, MaximumOrders, TakeoutCharge, Instructions, AllowPayMeLater, [SiteID]
	FROM         dbo.TakeoutProvider
	WHERE     (Id = @TakeoutProviderID)
	
	-- Takeout Users
	
	SELECT     Id, TakeoutProviderID, UserID, IsPaid, Instructions, OrderTime, FundsSecuredTime, OrderTotal
	FROM         dbo.TakeoutUser
	WHERE     (TakeoutProviderID = @TakeoutProviderID)
	
	-- TakeoutProviderAudiences
	
	SELECT     Id, AudienceId, TakeoutProviderId
	FROM         dbo.TakeoutProviderAudiences
	WHERE     (TakeoutProviderId = @TakeoutProviderId)
	
	-- Audiences
	
	SELECT     dbo.Audience.Id, dbo.Audience.Name, dbo.Audience.Description, dbo.Audience.[SiteID]
	FROM         dbo.TakeoutProviderAudiences INNER JOIN
	                      dbo.Audience ON dbo.TakeoutProviderAudiences.AudienceId = dbo.Audience.Id
	WHERE     (dbo.TakeoutProviderAudiences.TakeoutProviderId = @TakeoutProviderID)
	
	-- Payment Source
	
	SELECT     dbo.PaymentSource.Id, dbo.PaymentSource.Name, dbo.PaymentSource.AssemblyInfo
	FROM         dbo.PaymentSource INNER JOIN
	                      dbo.TakeoutProvider ON dbo.PaymentSource.Id = dbo.TakeoutProvider.PaymentSourceID
	WHERE     (dbo.TakeoutProvider.Id = @TakeoutProviderID)
	
	-- Payment Settings
	
	SELECT     Id, [Name], [Value], TakeoutProviderID
	FROM         dbo.PaymentSettings
	WHERE     (TakeoutProviderID = @TakeoutProviderID)
	
	-- Order Items
	
	SELECT     dbo.OrderItems.Id, dbo.OrderItems.TakeoutUserId, dbo.OrderItems.MenuItemID, dbo.OrderItems.Quantity, dbo.OrderItems.Instructions
	FROM         dbo.OrderItems INNER JOIN
	                      dbo.TakeoutUser ON dbo.OrderItems.TakeoutUserId = dbo.TakeoutUser.Id
	WHERE     (dbo.TakeoutUser.TakeoutProviderID = @TakeoutProviderID)
	
	-- Menu Items
		
	SELECT     dbo.MenuItems.Id, dbo.MenuItems.MenusId, dbo.MenuItems.Description, dbo.MenuItems.Price, dbo.MenuItems.PrepTimeMinutes, 
	                      dbo.TakeoutProvider.Id AS Expr1
	FROM         dbo.MenuItems INNER JOIN
	                      dbo.Menus ON dbo.MenuItems.MenusId = dbo.Menus.Id INNER JOIN
	                      dbo.TakeoutProvider ON dbo.Menus.Id = dbo.TakeoutProvider.MenuID
	WHERE     (dbo.TakeoutProvider.Id = @TakeoutProviderID)
	
	-- Menus
	
	SELECT     dbo.TakeoutProvider.Id AS Expr1, dbo.Menus.Id, dbo.Menus.CategoryId, dbo.Menus.Name, dbo.Menus.Address, dbo.Menus.City, dbo.Menus.State, 
	                      dbo.Menus.Zipcode, dbo.Menus.TaxRate
	FROM         dbo.Menus INNER JOIN
	                      dbo.TakeoutProvider ON dbo.Menus.Id = dbo.TakeoutProvider.MenuID
	WHERE     (dbo.TakeoutProvider.Id = @TakeoutProviderID)
	
	-- Category
	
	SELECT     dbo.TakeoutProvider.Id AS Expr1, dbo.Category.Id, dbo.Category.Name, dbo.Category.Description
	FROM         dbo.Menus INNER JOIN
	                      dbo.TakeoutProvider ON dbo.Menus.Id = dbo.TakeoutProvider.MenuID INNER JOIN
	                      dbo.Category ON dbo.Menus.CategoryId = dbo.Category.Id
	WHERE     (dbo.TakeoutProvider.Id = @TakeoutProviderID)
	

	RETURN


